﻿using System;
using System.Data;
using visinia.SmartEngine.Providers;

namespace viNews.Providers
{
    public abstract partial class viNewsDataProvider
    {
        #region INIT
        private static viNewsDataProvider _provider;
        private static object _lock = new object();

        public static viNewsDataProvider Provider
        {
            get { InternalInitialize(); return _provider; }
        }
        private static void InternalInitialize()
        {
            if (_provider == null)
            {
                lock (_lock)
                {
                    if (_provider == null)
                    {
                        _provider = (viNewsDataProvider)ProviderController.CreateDataProvider("viNews");
                        if (_provider == null)
                            throw new Exception("Unable to load default viNewsDataProvider");
                    }
                }
            }
        }
        #endregion

        #region NEWS
        public abstract IDataReader AddNews(string title, DateTime date, int category, string imageurl, string author, string summary, bool draft, string url, string description);
        public abstract void DeleteNews(int NewsId);
        public abstract void UpdateNews(int NewsId, string title, DateTime date, int category, string imageurl, string author, string summary, bool draft, string url, string description);
        public abstract IDataReader GetNews(int NewsId);
        public abstract IDataReader GetNews(int start, int count, bool PublishOnly);
        public abstract IDataReader GetNewsCount();
        public abstract IDataReader GetNewsDescription(int NewsId);
        public abstract IDataReader GetNewsByCategory(int Category, int Count);
        public abstract IDataReader GetNewsByTag(int Tag, int Count);
        public abstract IDataReader GetNewsCountByCategory(int CategoryId);
        public abstract IDataReader GetNewsCountByTag(int TagId);
        #endregion

        #region TAGS
        public abstract IDataReader GetTags();
        public abstract IDataReader GetTags(int EntryId);
        public abstract void InsertTag(int TagId, int EntryId);
        public abstract void RemoveTag(int TagId, int EntryId);
        public abstract IDataReader AddTag(string name);
        public abstract void DeleteTag(int TagId);
        #endregion

        #region CATEGORIES
        public abstract IDataReader GetCategories();
        public abstract void AddCategory(string Name, int ParentId, int PageId, int ContentPageId);
        public abstract void UpdateCategory(int CategoryId, string Name, int ParentId, int PageId, int ContentPageId);
        public abstract void DeleteCategory(int CategoryId);
        #endregion

        #region DATAFILTERS
        public abstract IDataReader GetFilters();
        public abstract void AddFilter(int FilterType, int ModuleId, string Data, int ItemsCount);
        public abstract void UpdateFilter(int FilterId, int FilterType, int ModuleId, string Data, int ItemsCount);
        public abstract void DeleteFilter(int FilterId);
        #endregion

        #region BASE SETTINGS
        public abstract void AddBaseSetting(string key, string value);
        public abstract void DeleteBaseSetting(string key);
        public abstract void UpdateBaseSetting(string key, string value);
        public abstract IDataReader GetBaseSettings();
        #endregion

        #region COMMENTS
        public abstract IDataReader GetComments(int NewsId);
        public abstract IDataReader GetRecentComments(int Count);
        public abstract IDataReader GetUnapprovedComments();
        public abstract IDataReader GetApprovedComments();
        public abstract IDataReader GetCommentsCount();
        public abstract void ApproveComment(int CommentId);
        public abstract void DeleteComment(int CommentId);
        public abstract void DeleteComments(int PostId);
        public abstract IDataReader AddComment(int NewsId, string Author, string Email, string Website, DateTime Date, string Content, bool IsApproved);
        #endregion
    }
}
